package com.ygk.bluepath.core;

import utils.SharedPreUtil;
import utils.ui.view.ProDialog_logo;

import java.util.HashMap;

import org.json.JSONObject;

import com.lidroid.xutils.DbUtils;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.umeng.analytics.MobclickAgent;
import com.umeng.message.PushAgent;
import com.ygk.bluepath.R;

import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

/**
 * 自定义一个抽象的MyActivity类，每个Activity都继承他，实现消息的接收（优化性能，减少代码重复）
 * 
 * @author way
 * 
 */
public abstract class BActivity extends FragmentActivity {

	protected BApp app = BApp.getInstance();
	public SharedPreUtil sp = app.getSharedPreUtil();
	public String root = app.getRoot();
	protected String Photos_cache = app.getmPicCache();
	public ImageLoader mImageLoader = app.getmImageLoader();
	public HashMap<String, Object> bMap=new HashMap<String, Object>();

	@Override
	protected void onCreate(Bundle arg0) {
		// TODO Auto-generated method stub
		super.onCreate(arg0);
		PushAgent.getInstance(this).onAppStart();
	}
	
	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();		
		//统计应用时长
		MobclickAgent.onResume(this);
	}
	
	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		//统计应用时长
		MobclickAgent.onPause(this);
	}
	
	/**
	 * @Description: TODO
	 * @param
	 * @return void
	 * @throws
	 */
	protected void disPlayImage(String Url, ImageView iv) {
		// TODO Auto-generated method stub
		mImageLoader.displayImage(Url, iv);
	}

	/**
	 * @Description: TODO
	 * @param
	 * @return void
	 * @throws
	 */
	protected void disPlayImage(String Url, ImageView iv,
			DisplayImageOptions dio) {
		// TODO Auto-generated method stub
		mImageLoader.displayImage(Url, iv, dio);
	}

/*	public void showLoading(boolean canCancle){
		ProDialog_logo.show(this, canCancle);
	}

	public void closeLoading(){
		ProDialog_logo.close();
	}*/

	public void tt(final String string) {
		// TODO Auto-generated method stub

		if (string != null && !string.equals("")) {
			runOnUiThread(new Runnable() {
				@Override
				public void run() {
					// TODO Auto-generated method stub
					Toast.makeText(app, string, Toast.LENGTH_SHORT).show();
				}
			});
		}

	}

	@Override
	public void onStart() {
		super.onStart();
		// setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);//横屏
		 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);//竖屏
		app.addActivity(this);

	}

	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		app.removeActivity(this);
		// mImageLoader.clearMemoryCache();

	}

	@Override
	public void onConfigurationChanged(Configuration newConfig) {
		super.onConfigurationChanged(newConfig);
	}

	/**
	 *
	 * @Description: 开启一个Activity (传统模式)
	 * @param : packageContext cls
	 * @return : void
	 * @throws
	 */
	protected void sta(Context packageContext, Class<?> cls) {
		startActivity(new Intent().setClass(packageContext, cls));
	}

	/**
	 *
	 * @Description: 开启一个Activity (带标识)
	 * @param : @param packageContext 从哪个activiyt开启
	 * @param : @param cls 到哪个activity
	 * @param : @param flag 标识
	 * @return : void
	 * @throws
	 */
	protected void staWFlg(Context packageContext, Class<?> cls, int flag) {
		startActivity(new Intent().setClass(packageContext, cls).setFlags(flag));
	}

	/**
	 *
	 * @Description: 开启一个Activity (Bundle模式)
	 * @param : packageContext cls
	 * @return : void
	 * @throws
	 */
	protected void staWBd(Context packageContext, Class<?> cls, Bundle bd) {
		startActivity(new Intent().setClass(packageContext, cls).putExtras(bd));
	}

}